home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 8 code / TValidText / UDateTimeText.inc1.p < prev    next >
Encoding:
Text File  |  1991-10-09  |  19.1 KB  |  792 lines  |  [TEXT/MPS ]

  1. {*******************************************************************************
  2. UDateTimeText.inc1.p
  3.     Classes implementing the ability to enter dates and times as text in
  4.     dialogs.
  5. *******************************************************************************}
  6.  
  7. CONST
  8.     kInvalidDateTimeAlert    = 701;        { the ValidationErrorAlert() alert }
  9.  
  10. {###############################################################################
  11. Implementation Globals (global extent, local scope)
  12. ###############################################################################}
  13.  
  14. VAR
  15.     pDefaultDateForm:    DateForm;        { used by TDateEditText }
  16.     
  17.  
  18.  
  19. {###############################################################################
  20. Global Routines
  21. ###############################################################################}
  22.  
  23. {------------------------------------------------------------------------------}
  24. {$S AInit}
  25.                         
  26. PROCEDURE InitUDateTimeText(
  27.                         theDateForm:    DateForm);
  28.     VAR
  29.         dummy:        BOOLEAN;
  30.     
  31.     BEGIN
  32.     IF gDeadStripSuppression
  33.     THEN
  34.         BEGIN
  35.         { view classes }
  36.         dummy := Member(TObject(NIL), TDateEditText);
  37.         dummy := Member(TObject(NIL), TTimeEditText);
  38.         END;  { then }
  39.     
  40.     SetDefaultDateForm(theDateForm);
  41.     END;  { InitUDateTimeText }
  42.  
  43. {------------------------------------------------------------------------------}
  44. {$S Date_Seg}
  45.                         
  46. PROCEDURE SetDefaultDateForm(
  47.                         theDateForm:    DateForm);
  48.     BEGIN
  49.     pDefaultDateForm := theDateForm;
  50.     END;  { SetDefaultDateForm }
  51.  
  52. {------------------------------------------------------------------------------}
  53. {$S Date_Seg}
  54.                         
  55. FUNCTION  GetDefaultDateForm
  56.                         :DateForm;
  57.     BEGIN
  58.     GetDefaultDateForm := pDefaultDateForm;
  59.     END;  { GetDefaultDateForm }
  60.  
  61.  
  62.  
  63. {###############################################################################
  64. TDateEditText
  65. ###############################################################################}
  66.  
  67. {------------------------------------------------------------------------------}
  68. {$S DlgOpen}
  69.  
  70. PROCEDURE TDateEditText.IDateEditText(
  71.                         itsSuperView:    TView;
  72.                         itsLocation:    VPoint;
  73.                         itsSize:        VPoint;
  74.                         strict:            BOOLEAN;
  75.                         required:        BOOLEAN;
  76.                         itsDateForm:    INTEGER;
  77.                         itsDateSecs:    LongDateTime);
  78.     
  79.     BEGIN
  80.     IValidText(itsSuperView, itsLocation, itsSize,
  81.                strict, required, kInvalidDateTimeAlert);
  82.     
  83.     { set the dates format }
  84.     fDateForm := itsDateForm;
  85.     
  86.     { set the initial string to match fDateSecs }
  87.     SetDateSecs(itsDateSecs, kDontRedraw);
  88.     END;  { IDateEditText }
  89.  
  90. {------------------------------------------------------------------------------}
  91. {$S DlgOpen}
  92.  
  93. PROCEDURE TDateEditText.IRes(
  94.                         itsDocument:    TDocument;
  95.                         itsSuperView:    TView;
  96.                     VAR itsParams:        Ptr);
  97.                         OVERRIDE;
  98.     VAR
  99.         theText:        Str255;
  100.         theDate:        LongDateTime;
  101.         result:            String2DateStatus;
  102.     
  103.     BEGIN
  104.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  105.     
  106.     { read extra field from resource }
  107.     WITH DateTextTemplatePtr(itsParams)^ DO
  108.         BEGIN
  109.         fDateForm := theDateForm;
  110.         (*
  111.         {$IFC qDebug}
  112.         writeln;
  113.         writeln('In TDateEditText.IRes()');
  114.         write  ('           fIdentifier = '); WriteSig(fIdentifier); writeln;
  115.         writeln('           theDateForm = ', theDateForm:1);
  116.         {$ENDC qDebug}
  117.         *)
  118.         END;
  119.  
  120.     { offset the itsParam ptr accordingly }
  121.     OffsetPtr(itsParams, SIZEOF(DateTextTemplate));
  122.     
  123.     { convert the initial text to a date, and set fDateSecs to that date }
  124.     GetText(theText);
  125.     result := StringToDate(theText, theDate);
  126.     SetDateSecs(theDate, kDontRedraw);
  127.     END;  { IRes }
  128.  
  129.  
  130. {------------------------------------------------------------------------------}
  131. {$S MAWriteRes}
  132.  
  133. PROCEDURE TDateEditText.WRes(
  134.                         theResource:    ViewRsrcHndl;
  135.                     VAR    itsParams:        Ptr);
  136.                         OVERRIDE;
  137.  
  138.     VAR
  139.         p:                DateTextTemplatePtr;
  140.  
  141.     BEGIN
  142.     INHERITED WRes(theResource, itsParams);
  143.     
  144.     p := DateTextTemplatePtr(ExpandPtr(theResource,
  145.                                        itsParams,
  146.                                        SIZEOF(DateTextTemplate)));
  147.     
  148.     WITH p^ DO
  149.         BEGIN
  150.         theDateForm := fDateForm;
  151.         END;
  152.     END;  { WRes }
  153.  
  154.  
  155. {------------------------------------------------------------------------------}
  156. {$S MAWriteRes}
  157.  
  158. PROCEDURE TDateEditText.WriteRes(
  159.                         theResource:    ViewRsrcHndl;
  160.                     VAR itsParams:        Ptr);
  161.                         OVERRIDE;
  162.  
  163.     BEGIN
  164.     gWResSignature := 'date';    { See ViewResourceTypes.r }
  165.     gWResType := 'TDateEditText';
  166.     WRes(theResource, itsParams);
  167.     END;  { WriteRes }
  168.  
  169. {------------------------------------------------------------------------------}
  170. {$S DlgNonRes}
  171.         
  172. PROCEDURE TDateEditText.SetDateSecs(
  173.                         dateSecs:        LongDateTime;
  174.                         redraw:            BOOLEAN);
  175.     
  176.     BEGIN
  177.     fDateSecs := dateSecs;
  178.         
  179.     UpdateText(redraw);
  180.     END;  { SetDateSecs }
  181.  
  182. {------------------------------------------------------------------------------}
  183. {$S DlgNonRes}
  184.  
  185. PROCEDURE TDateEditText.SetDateForm(
  186.                         theDateForm:    INTEGER;
  187.                         redraw:            BOOLEAN);
  188.  
  189.     BEGIN
  190.     fDateForm := theDateForm;
  191.     
  192.     UpdateText(redraw);
  193.     END;  { SetDateForm }
  194.  
  195. {------------------------------------------------------------------------------}
  196. {$S DlgRes}
  197.  
  198. FUNCTION  TDateEditText.GetDateSecs
  199.                         :LongDateTime;
  200.     BEGIN
  201.     GetDateSecs := fDateSecs;
  202.     END;  { GetDateSecs }
  203.  
  204. {------------------------------------------------------------------------------}
  205. {$S DlgRes}
  206.  
  207. FUNCTION  TDateEditText.GetDateForm
  208.                         :INTEGER;
  209.     BEGIN
  210.     GetDateForm := fDateForm;
  211.     END;  { GetDateForm }
  212.  
  213. {------------------------------------------------------------------------------}
  214. {$S DlgRes}
  215.  
  216. FUNCTION  TDateEditText.CurrentDateForm
  217.                         :DateForm;
  218.     BEGIN
  219.     IF (fDateForm = kDefDateForm)
  220.     THEN
  221.         CurrentDateForm := GetDefaultDateForm    { use global DateForm }
  222.     ELSE
  223.         CurrentDateForm := DateForm(fDateForm);    { use object's DateForm }
  224.     END;  { CurrentDateForm }
  225.  
  226. {------------------------------------------------------------------------------}
  227. {$S DlgRes}
  228.         
  229. PROCEDURE TDateEditText.UpdateText(
  230.                         redraw:            BOOLEAN);
  231.                         OVERRIDE;
  232.     { This routine replaces the text in the object with text that reflects
  233.         the object's fDateSecs and fDateForm values. }
  234.         
  235.     VAR
  236.         dateSecs:        LongDateTime;
  237.         dateString:        Str255;
  238.     
  239.     BEGIN
  240.     dateSecs := GetDateSecs;
  241.     
  242.     IF (dateSecs = kNotADate)
  243.     THEN
  244.         SetText('', redraw)
  245.     ELSE
  246.         BEGIN
  247.         DateToString(dateSecs, CurrentDateForm, dateString);
  248.         SetText(dateString, redraw);
  249.         END;
  250.     END;  { UpdateText }
  251.  
  252. {------------------------------------------------------------------------------}
  253. {$S DlgNonRes}
  254.  
  255. FUNCTION  TDateEditText.IsValid(
  256.                     VAR    theText:        Str255;
  257.                     VAR    whyNot:            INTEGER)
  258.                         :BOOLEAN;
  259.                         OVERRIDE;
  260.     { If the text is valid, then this function returns TRUE, and whyNot
  261.         is set to the value noErr (0).  If the text is invalid, then the
  262.         function returns FALSE and whyNot is set to a value indicating
  263.         the reason why the text is invalid. }
  264.     
  265.     VAR
  266.         theError:        INTEGER;
  267.         valid:            BOOLEAN;
  268.         dateSecs:        LongDateTime;
  269.     
  270.     BEGIN
  271.     IF (NOT INHERITED IsValid(theText, theError))
  272.     THEN
  273.         BEGIN
  274.         valid  := FALSE;
  275.         whyNot := theError;
  276.         END
  277.     ELSE
  278.         BEGIN
  279.         theError := StringToDate(theText, dateSecs);
  280.         
  281.         IF fStrict
  282.         THEN
  283.             valid := (theError = noErr) | (theError = longDateFound)
  284.         ELSE
  285.             valid := (theError >= noErr);
  286.         
  287.         IF (theError = dateTimeNotFound) &    { no date was found }
  288.            (NOT fRequired) &                { empty strings are OK }
  289.            (Length(theText) = 0)            { and the string is empty }
  290.         THEN
  291.             valid := TRUE;  { empty string OK if entry is not required }
  292.         
  293.         IF valid
  294.         THEN
  295.             whyNot := noErr
  296.         ELSE
  297.             whyNot := theError;
  298.         END;
  299.     
  300.     IsValid := valid;
  301.     
  302.     (*
  303.     {$IFC qDebug}
  304.         writeln;
  305.         writeln('In TDateEditText.IsValid():');
  306.         writeln('                theText = "', theText, '"');
  307.         write  ('                 whyNot = '); WriteHexInt(whyNot); writeln;
  308.         write  ('               theError = '); WriteHexInt(theError); writeln;
  309.         write  ('                  valid = '); WriteBoolean(valid); writeln;
  310.     {$ENDC qDebug}
  311.     *)
  312.     END;  { IsValid }
  313.  
  314. {------------------------------------------------------------------------------}
  315. {$S DlgNonRes}
  316.  
  317. FUNCTION  TDateEditText.HandleValidText(
  318.                     VAR    theText:        Str255)
  319.                         :LONGINT;
  320.                         OVERRIDE;
  321.     { This routine always returns kValidValue.  In its OVERRIDES, it
  322.         might update SELF's internal instance variables to reflect
  323.         the valid text. }
  324.     VAR
  325.         status:            String2DateStatus;
  326.         dateSecs:        LongDateTime;
  327.     
  328.     BEGIN
  329.     { We already called StringToDate() in IsValid(), and lost the result; but
  330.         a little redundancy never hurts.  A little redundancy never hurts. }
  331.     status := StringToDate(theText, dateSecs);
  332.     SetDateSecs(dateSecs, kRedraw);
  333.     
  334.     HandleValidText := INHERITED HandleValidText(theText);
  335.     END;  { HandleValidText }
  336.  
  337. {------------------------------------------------------------------------------}
  338. {$S DlgNonRes}
  339.  
  340. PROCEDURE TDateEditText.ErrorToString(
  341.                         theError:        INTEGER;
  342.                     VAR    theString:        Str255);
  343.                         OVERRIDE;
  344.     { This routine sets theString to the string which best explains
  345.         the given error.  It is intended to be called only from
  346.         PrepareErrorAlert(). }
  347.     VAR
  348.         strIndex:        INTEGER;
  349.     
  350.     BEGIN
  351.     CASE theError OF
  352.         leftOverChars:        strIndex :=  2;
  353.         sepNotIntlSep:        strIndex :=  3;
  354.         fieldOrderNotIntl:    strIndex :=  4;
  355.         extraneousStrings:    strIndex :=  5;
  356.         tooManySeps:        strIndex :=  6;
  357.         sepNotConsistent:    strIndex :=  7;
  358.         tokenErr:            strIndex :=  8;
  359.         cantReadUtilities:    strIndex :=  9;
  360.         dateTimeNotFound:    strIndex := 10;
  361.         dateTimeInvalid:    strIndex := 11;
  362.             
  363.         OTHERWISE            strIndex :=  0;
  364.         END;  { case theError }
  365.     
  366.     IF (strIndex > 0)
  367.     THEN
  368.         GetIndString(theString, kInvalidDateReasons, strIndex)
  369.     ELSE
  370.         INHERITED ErrorToString(theError, theString);
  371.     
  372.     (*
  373.     {$IFC qDebug}
  374.     writeln;
  375.     write('In TDateEditText.ErrorToString(), theString = "', theString,
  376.           '" and theError = ');
  377.     WriteHexInt(theError);
  378.     writeln;
  379.     {$ENDC qDebug}
  380.     *)
  381.     END;  { ErrorToString }
  382.  
  383. {------------------------------------------------------------------------------}
  384. {$S DlgNonRes}
  385.  
  386. PROCEDURE TDateEditText.PrepareErrorAlert(
  387.                     VAR    theText:        Str255;
  388.                         theError:        INTEGER);
  389.                         OVERRIDE;
  390.     { The routine sets up the dialog that is displayed by
  391.         ValidationErrorAlert(). }
  392.     
  393.     VAR
  394.         errString:        Str255;
  395.         dateSecs:        LongDateTime;
  396.         dateString:        Str255;
  397.     
  398.     BEGIN
  399.     { get the best string to describe the given error }
  400.     ErrorToString(theError, errString);
  401.     
  402.     { get the current date, as a string }
  403.     GetCurrentDate(dateSecs);
  404.     DateToString(dateSecs, shortDate, dateString);
  405.     
  406.     ParamText(errString, dateString, '', '');
  407.     END;  { PrepareErrorAlert }
  408.  
  409. {------------------------------------------------------------------------------}
  410. {$S DlgFields}
  411.                         
  412. {$IFC qInspector}
  413. PROCEDURE TDateEditText.Fields(
  414.                         PROCEDURE DoToField(
  415.                             fieldName:        Str255;
  416.                             fieldAddr:        Ptr;
  417.                             fieldType:        INTEGER));
  418.                         OVERRIDE;
  419.     VAR
  420.         aStr:            Str255;
  421.         theSecs:        LongDateTime;
  422.         
  423.     BEGIN
  424.     DoToField('TDateEditText', NIL, bClass);
  425.     
  426.     CASE fDateForm OF
  427.         ord(shortDate):        aStr := 'shortDate';
  428.         ord(longDate):        aStr := 'longDate';
  429.         ord(abbrevDate):    aStr := 'abbrevDate';
  430.         kDefDateForm:        aStr := 'defDateForm';
  431.         OTHERWISE            aStr := '<unknown>';
  432.         END;  { case fDateForm }
  433.         
  434.     DoToField('fDateForm', @aStr, bString);
  435.     
  436.     { now, the fDateSecs field }
  437.     theSecs := fDateSecs;
  438.     DateToString(theSecs, abbrevDate, aStr);
  439.     DoToField('fDateSecs', @aStr, bString);
  440.  
  441.     INHERITED Fields(DoToField);
  442.     END;  { Fields }
  443. {$ENDC qDebug}
  444.  
  445.  
  446.  
  447. {###############################################################################
  448. TTimeEditText
  449. ###############################################################################}
  450.  
  451. {------------------------------------------------------------------------------}
  452. {$S DlgOpen}
  453.  
  454. PROCEDURE TTimeEditText.ITimeEditText(
  455.                         itsSuperView:    TView;
  456.                         itsLocation:    VPoint;
  457.                         itsSize:        VPoint;
  458.                         strict:            BOOLEAN;
  459.                         required:        BOOLEAN;
  460.                         wantSeconds:    BOOLEAN;
  461.                         itsTimeSecs:    LONGINT);
  462.     
  463.     BEGIN
  464.     IValidText(itsSuperView, itsLocation, itsSize,
  465.                strict, required, kInvalidDateTimeAlert);
  466.     
  467.     fWantSeconds := wantSeconds;
  468.     
  469.     { set the initial string to match fTimeSecs }
  470.     SetTimeSecs(itsTimeSecs, kDontRedraw);
  471.     END;  { ITimeEditText }
  472.  
  473. {------------------------------------------------------------------------------}
  474. {$S DlgOpen}
  475.  
  476. PROCEDURE TTimeEditText.IRes(
  477.                         itsDocument:    TDocument;
  478.                         itsSuperView:    TView;
  479.                     VAR itsParams:        Ptr);
  480.                         OVERRIDE;
  481.     VAR
  482.         theText:        Str255;
  483.         theTime:        LONGINT;
  484.         result:            String2DateStatus;
  485.     
  486.     BEGIN
  487.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  488.     
  489.     { read extra field from resource }
  490.     WITH TimeTextTemplatePtr(itsParams)^ DO
  491.         BEGIN
  492.         fWantSeconds  := wantSeconds;
  493.         END;
  494.  
  495.     { offset the itsParam ptr accordingly }
  496.     OffsetPtr(itsParams, SIZEOF(TimeTextTemplate));
  497.     
  498.     { set fTimeSecs to match the initial string }
  499.     GetText(theText);
  500.     result := StringToTime(theText, theTime);
  501.     SetTimeSecs(theTime, kDontRedraw);
  502.     END;  { IRes }
  503.  
  504.  
  505. {------------------------------------------------------------------------------}
  506. {$S MAWriteRes}
  507.  
  508. PROCEDURE TTimeEditText.WRes(
  509.                         theResource:    ViewRsrcHndl;
  510.                     VAR    itsParams:        Ptr);
  511.                         OVERRIDE;
  512.  
  513.     VAR
  514.         p:                TimeTextTemplatePtr;
  515.  
  516.     BEGIN
  517.     INHERITED WRes(theResource, itsParams);
  518.     
  519.     p := TimeTextTemplatePtr(ExpandPtr(theResource,
  520.                                        itsParams,
  521.                                        SIZEOF(TimeTextTemplate)));
  522.     
  523.     WITH p^ DO
  524.         BEGIN
  525.         wantSeconds := fWantSeconds;
  526.         reserved := FALSE;
  527.         END;
  528.     END;  { WRes }
  529.  
  530.  
  531. {------------------------------------------------------------------------------}
  532. {$S MAWriteRes}
  533.  
  534. PROCEDURE TTimeEditText.WriteRes(
  535.                         theResource:    ViewRsrcHndl;
  536.                     VAR itsParams:        Ptr);
  537.                         OVERRIDE;
  538.  
  539.     BEGIN
  540.     gWResSignature := 'time';    { See ViewResourceTypes.r }
  541.     gWResType := 'TTimeEditText';
  542.     WRes(theResource, itsParams);
  543.     END;  { WriteRes }
  544.  
  545. {------------------------------------------------------------------------------}
  546. {$S DlgNonRes}
  547.         
  548. PROCEDURE TTimeEditText.SetTimeSecs(
  549.                         timeSecs:        LONGINT;
  550.                         redraw:            BOOLEAN);
  551.     
  552.     BEGIN
  553.     fTimeSecs := timeSecs;
  554.         
  555.     UpdateText(redraw);
  556.     END;  { SetTimeSecs }
  557.  
  558. {------------------------------------------------------------------------------}
  559. {$S DlgNonRes}
  560.         
  561. PROCEDURE TTimeEditText.SetWantSeconds(
  562.                         wantSeconds:    BOOLEAN;
  563.                         redraw:            BOOLEAN);
  564.     BEGIN
  565.     fWantSeconds := wantSeconds;
  566.  
  567.     UpdateText(redraw);
  568.     END;  { SetWantSeconds }
  569.  
  570. {------------------------------------------------------------------------------}
  571. {$S DlgRes}
  572.         
  573. FUNCTION  TTimeEditText.GetTimeSecs
  574.                         :LONGINT;
  575.     BEGIN
  576.     GetTimeSecs := fTimeSecs;
  577.     END;  { GetTimeSecs }
  578.  
  579. {------------------------------------------------------------------------------}
  580. {$S DlgRes}
  581.         
  582. FUNCTION  TTimeEditText.GetWantSeconds
  583.                         :BOOLEAN;
  584.     BEGIN
  585.     GetWantSeconds := fWantSeconds;
  586.     END;  { GetWantSeconds }
  587.  
  588. {------------------------------------------------------------------------------}
  589. {$S DlgRes}
  590.         
  591. PROCEDURE TTimeEditText.UpdateText(
  592.                         redraw:            BOOLEAN);
  593.                         OVERRIDE;
  594.     { This routine replaces the text in the object with text that reflects
  595.         the object's fTimeSecs and fWantSeconds values. }
  596.         
  597.     VAR
  598.         timeSecs:        LONGINT;
  599.         timeString:        Str255;
  600.     
  601.     BEGIN
  602.     timeSecs := GetTimeSecs;
  603.     
  604.     IF (timeSecs = kNotATime)
  605.     THEN
  606.         SetText('', redraw)
  607.     ELSE
  608.         BEGIN
  609.         TimeToString(timeSecs, fWantSeconds, timeString);
  610.         SetText(timeString, redraw);
  611.         END;
  612.     END;  { UpdateText }
  613.  
  614. {------------------------------------------------------------------------------}
  615. {$S DlgNonRes}
  616.  
  617. FUNCTION  TTimeEditText.IsValid(
  618.                     VAR    theText:        Str255;
  619.                     VAR    whyNot:            INTEGER)
  620.                         :BOOLEAN;
  621.                         OVERRIDE;
  622.     { If the text is valid, then this function returns TRUE, and whyNot
  623.         is set to the value noErr (0).  If the text is invalid, then the
  624.         function returns FALSE and whyNot is set to a value indicating
  625.         the reason why the text is invalid. }
  626.     
  627.     VAR
  628.         theError:        INTEGER;
  629.         valid:            BOOLEAN;
  630.         timeSecs:        LONGINT;
  631.     
  632.     BEGIN
  633.     IF (NOT INHERITED IsValid(theText, theError))
  634.     THEN
  635.         BEGIN
  636.         valid := FALSE;
  637.         whyNot := theError;
  638.         END
  639.     ELSE
  640.         BEGIN
  641.         theError := StringToTime(theText, timeSecs);
  642.         
  643.         IF fStrict
  644.         THEN
  645.             valid := (theError = noErr) | (theError = longDateFound)
  646.         ELSE
  647.             valid := (theError >= noErr);
  648.         
  649.         IF (theError = dateTimeNotFound) &    { no date was found }
  650.            (NOT fRequired) &                { empty strings are OK }
  651.            (Length(theText) = 0)            { and the string is empty }
  652.         THEN
  653.             valid := TRUE;
  654.         
  655.         IF valid
  656.         THEN
  657.             whyNot := noErr
  658.         ELSE
  659.             whyNot := theError;
  660.         END;
  661.     
  662.     IsValid := valid;
  663.     
  664.     {$IFC qDebug}
  665.         (*
  666.         writeln;
  667.         WrLblHexInt('In TTimeEditText.IsValid(), theError', theError);
  668.         writeln;
  669.         WrLblHexInt('                              whyNot', whyNot);
  670.         writeln;
  671.         WrLblBoolean('                               valid', valid);
  672.         writeln;
  673.         *)
  674.     {$ENDC qDebug}
  675.     END;  { IsValid }
  676.  
  677. {------------------------------------------------------------------------------}
  678. {$S DlgNonRes}
  679.  
  680. FUNCTION  TTimeEditText.HandleValidText(
  681.                     VAR    theText:        Str255)
  682.                         :LONGINT;
  683.                         OVERRIDE;
  684.     { This routine always returns kValidValue.  In its OVERRIDES, it
  685.         might update SELF's internal instance variables to reflect
  686.         the valid text. }
  687.     VAR
  688.         status:            String2DateStatus;
  689.         timeSecs:        LONGINT;
  690.     
  691.     BEGIN
  692.     { We already called StringToTime() in IsValid(), and lost the result; but
  693.         a little redundancy never hurts.  A little redundancy never hurts. }
  694.     status := StringToTime(theText, timeSecs);
  695.     SetTimeSecs(timeSecs, kRedraw);
  696.     
  697.     HandleValidText := kValidValue;
  698.     END;  { HandleValidText }
  699.  
  700. {------------------------------------------------------------------------------}
  701. {$S DlgNonRes}
  702.  
  703. PROCEDURE TTimeEditText.ErrorToString(
  704.                         theError:        INTEGER;
  705.                     VAR    theString:        Str255);
  706.                         OVERRIDE;
  707.     { This routine sets theString to the string which best explains
  708.         the given error.  It is intended to be called only from
  709.         PrepareErrorAlert(). }
  710.     VAR
  711.         strIndex:        INTEGER;
  712.     
  713.     BEGIN
  714.     CASE theError OF
  715.         leftOverChars:        strIndex :=  2;
  716.         sepNotIntlSep:        strIndex :=  3;
  717.         fieldOrderNotIntl:    strIndex :=  4;
  718.         extraneousStrings:    strIndex :=  5;
  719.         tooManySeps:        strIndex :=  6;
  720.         sepNotConsistent:    strIndex :=  7;
  721.         tokenErr:            strIndex :=  8;
  722.         cantReadUtilities:    strIndex :=  9;
  723.         dateTimeNotFound:    strIndex := 10;
  724.         dateTimeInvalid:    strIndex := 11;
  725.             
  726.         OTHERWISE            strIndex :=  0;
  727.         END;  { case theError }
  728.     
  729.     IF (strIndex > 0)
  730.     THEN
  731.         GetIndString(theString, kInvalidTimeReasons, strIndex)
  732.     ELSE
  733.         INHERITED ErrorToString(theError, theString);
  734.     
  735.     {$IFC qDebug}
  736.     (*
  737.     writeln;
  738.     write('In TDateEditText.ErrorToString(), theString = "', theString,
  739.           '" and theError = ');
  740.     WriteHexInt(theError);
  741.     writeln;
  742.     *)
  743.     {$ENDC qDebug}
  744.     END;  { ErrorToString }
  745.  
  746. {------------------------------------------------------------------------------}
  747. {$S DlgNonRes}
  748.  
  749. PROCEDURE TTimeEditText.PrepareErrorAlert(
  750.                     VAR    theText:        Str255;
  751.                         theError:        INTEGER);
  752.                         OVERRIDE;
  753.     { The routine sets up the dialog that is displayed by
  754.         ValidationErrorAlert(). }
  755.     
  756.     VAR
  757.         errString:        Str255;
  758.         timeSecs:        LONGINT;
  759.         timeString:        Str255;
  760.     
  761.     BEGIN
  762.     { get the best string to describe the given error }
  763.     ErrorToString(theError, errString);
  764.     
  765.     { get the current time, as a string }
  766.     GetCurrentTime(timeSecs);
  767.     TimeToString(timeSecs, kDontWantSeconds, timeString);
  768.     
  769.     ParamText(errString, timeString, '', '');
  770.     END;  { PrepareErrorAlert }
  771.  
  772. {------------------------------------------------------------------------------}
  773. {$S DlgFields}
  774.                         
  775. {$IFC qInspector}
  776. PROCEDURE TTimeEditText.Fields(
  777.                         PROCEDURE DoToField(
  778.                             fieldName:        Str255;
  779.                             fieldAddr:        Ptr;
  780.                             fieldType:        INTEGER));
  781.                         OVERRIDE;
  782.     BEGIN
  783.     DoToField('TTimeEditText', NIL, bClass);
  784.     
  785.     DoToField('fTimeSecs',        @fTimeSecs,        bLongint);
  786.     DoToField('fWantSeconds',    @fWantSeconds,    bBoolean);
  787.  
  788.     INHERITED Fields(DoToField);
  789.     END;  { Fields }
  790. {$ENDC qDebug}
  791.  
  792. {------------------------------------------------------------------------------}